;; First define templates for the model classes so we can use them
;; in our pricing rules. This doesn't create any model objects --
;; it just tells Jess to examine the classes and set up templates
;; using their properties

(import jesstest.model.*)
(deftemplate Problem     (declare (from-class Problem)))
(deftemplate Profile     (declare (from-class Profile)))
(deftemplate Communication (declare (from-class Communication)))
(deftemplate EquipmentConfig (declare (from-class EquipmentConfig)))

;; Now define the pricing rules themselves. Each rule matches a set
;; of conditions and then creates an Offer object to represent a
;; bonus of some kind given to a customer. The rules assume that
;; there will be just one Order, its OrderItems, and its Customer in 
;; working memory, along with all the CatalogItems.



(defrule Send-conditions
	"If this profile has less than 5 problems and the following conditions about problems size and link are met then we should add him to the send list." 
;; (Profile.activeEquipmentConfig {communication = Communication.GPRS})	
;;	 (or (and (Problem {sizeInKb <= 1024}) (Profile {currentNumberOfProblems < 5 })) 
;;	     (and (Problem {sizeInKb <= 10240}) (Profile.activeEquipmentConfig {communication = Communication.NG}) (Profile {currentNumberOfProblems<5}))
;;	     (and (Profile.activeEquipmentConfig {communication = Communication.WIFI}) (Profile {currentNumberOfProblems<5}) ) )
	
	
 	(or (and (Profile {currentNumberOfProblems < 5 }) (Problem {sizeInKb <= 1024})  (EquipmentConfig {communication == 1}) ) ;; GPRS
	    (and (Profile {currentNumberOfProblems < 5}) (Problem {sizeInKb <= 10240}) (EquipmentConfig {communication == 2}) )  ;; NG
	 	(and (Profile {currentNumberOfProblems < 5}) (EquipmentConfig {communication == 3}) )
	 )	
	  => (add (new Selected))
 
  
;; Working variant
;;	(or (and (Profile {currentNumberOfProblems < 5 }) (Problem {sizeInKb <= 1024})  (Profile {communication == 1}) ) ;; GPRS
;;	    (and (Profile {currentNumberOfProblems < 5}) (Problem {sizeInKb <= 10240}) (Profile {communication == 2}) )  ;; NG
;;	 	(and (Profile {currentNumberOfProblems < 5}) (Profile {communication == 3}) )
;;	 )	
;;	  => (add (new Selected))
)
